package cn.lanqiao.facelogin.faceData;

import com.aliyun.tea.*;
import com.aliyun.facebody20191230.*;
import com.aliyun.facebody20191230.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.Common;

public class AddFace {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new com.aliyun.facebody20191230.Client(config);
    }

    public static Boolean addFace(String setImageUrl,String setEntityId){

        com.aliyun.facebody20191230.Client client = null;
        try {
            client = createClient("LTAI5tHNDzFHTvU8ZuETPGY9", "FxOXeVcFkA8Q7UuHFnTxGQDnSGqkhb");
            AddFaceRequest addFaceRequest = new AddFaceRequest()
                    .setDbName("FaceData")
                    .setImageUrl("https://demo55.oss-cn-shanghai.aliyuncs.com/p127462.png?Expires=1645561291&OSSAccessKeyId=TMP.3KiPmGqUqxar3kzC7UhFxZz92ydKhDF8VdLddRUcRXsSKV1sfRupGghwCxQpCRKsgzeBvdHvWruyRE2i4ue1tTVFyvywWF&Signature=MXalRAEkKmt8RWHRg6qzwjjmAiY%3D")
                    .setEntityId("1999");
            // 复制代码运行请自行打印 API 的返回值
            AddFaceResponse addFaceResponse = client.addFace(addFaceRequest);
//            String s = Common.toJSONString(addFaceResponse);
            return true;
        } catch (Exception e) {
            System.out.println("添加人脸数据失败");
        }
        return false;
    }
}
